{	Problem: http://codeforces.ru/problemset/problem/16/A
	Verdict: Accepted

}
var i,j,n,m,k:longint; s:string; a:Array[0..101,0..101] of integer;  res:boolean;
begin
readln(n,m);
fillchar(a,sizeof(a),0);
for i:=1 to m do a[0][i]:=-1;
for i:=1 to n do begin
  readln(s);
  for j:=1 to m do begin
    a[i][j]:=ord(s[j])-48;
  end;
end;
res:=true;
for i:=1 to n do begin
if res then begin
  k:=a[i][1];
  if k=a[i-1][1] then res:=false else begin
    for j:=2 to m do  if a[i][j]<>k then res:=false;
  end;
end;
end;
if res then writeln('YES') else writeln('NO');
end.